if (SERVER) then
	AddCSLuaFile("shared.lua");
end;

if (CLIENT) then
	SWEP.Slot			= 1;
	SWEP.SlotPos		= 1;
	SWEP.ViewModelFlip 	= false;
	SWEP.DrawAmmo 		= false;
	SWEP.ViewModelFOV	= 62;
end;

SWEP.Base = "lgtrp_weapon_base";

SWEP.PrintName			= "Keys";
SWEP.Instructions		 = "Left click to hit.";

SWEP.AdminSpawnable		= true;

SWEP.WorldModel 		= Model("models/weapons/w_fists.mdl");
SWEP.ViewModel			= Model("models/weapons/v_fists.mdl");

SWEP.Primary.ClipSize		= 1;
SWEP.Primary.DefaultClip	= 1;
SWEP.Primary.Automatic		= false;
SWEP.Primary.Ammo			= "none";

SWEP.Secondary.ClipSize		= 1;
SWEP.Secondary.DefaultClip	= 1;
SWEP.Secondary.Automatic	= false;
SWEP.Secondary.Ammo			= "none";

function SWEP:Initialize()
	self.HoldType = "normal";
	self.holsterType = "normal";
end;

function SWEP:Deploy()
	if (SERVER) then
		self.Owner:DrawViewModel(false);
		self.Owner:DrawWorldModel(false);
	end;
end;

function SWEP:Reload()
end;

function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() +0.3);
	
	if (SERVER) then
		local tr = self.Owner:EyeTrace(100);
	
		if (IsValid(tr.Entity) and tr.Entity:IsDoor()) then
			local class = self.Owner:GetClassData();
			
			if (class.combine) then
				local owner = tr.Entity:GetDoorOwner();
				
				if (owner and #owner == 1) then
					owner = owner[1];
					
					if (owner == "combine") then
						tr.Entity:Fire("lock", "", 0);
						self.Owner:EmitSound("doors/door_latch1.wav");
						
						return;
					end;
				end;
			end;
			
			local isOwner = tr.Entity:HasDoorOwner(self.Owner);

			if (isOwner) then
				tr.Entity:Fire("lock", "", 0);
				self.Owner:EmitSound("doors/door_latch1.wav");
			end;
		end;
	end;
end;

function SWEP:SecondaryAttack()
	self.Weapon:SetNextSecondaryFire(CurTime() +0.3);
	
	if (SERVER) then
		local tr = self.Owner:EyeTrace(100);
	
		if (IsValid(tr.Entity) and tr.Entity:IsDoor()) then
			local class = self.Owner:GetClassData();
			
			if (class.combine) then
				local owner = tr.Entity:GetDoorOwner();
				
				if (owner and #owner == 1) then
					owner = owner[1];
					
					if (owner == "combine") then
						tr.Entity:Fire("unlock", "", 0);
						self.Owner:EmitSound("doors/door_latch3.wav");
						
						return;
					end;
				end;
			end;
			
			local isOwner = tr.Entity:HasDoorOwner(self.Owner);

			if (isOwner) then
				tr.Entity:Fire("unlock", "", 0);
				self.Owner:EmitSound("doors/door_latch3.wav");
			end;
		end;
	end;
end;